package org.ly817.busCode.core.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
import io.netty.handler.codec.protobuf.ProtobufEncoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
import org.ly817.busCode.protocol.protobuf.BusCode;
import org.ly817.busCode.protocol.protobuf.BusCodeHandler;

/**
 * @author LuoYu
 * @date 2019/02/19 14:53
 * <p>
 * Description:
 */
public class DemoInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline()
                .addLast(new ProtobufEncoder())
                .addLast(new ProtobufVarint32FrameDecoder())
                .addLast(new ProtobufVarint32LengthFieldPrepender())
                .addLast(new ProtobufDecoder(BusCode.busMsg.getDefaultInstance()))
                .addLast(new BusCodeHandler());
    }
}
